import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Card } from 'antd';
import moment from 'moment';
import StandardTable from '@/components/StandardTable';

@connect(({ integratedqueryns, loading }) => ({
  loading: loading.models.integratedqueryns,
  addTaskList: integratedqueryns.addTaskList, // 增员任务列表数据
}))
@Form.create()
class EmpInfor extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {}

  jumpRouting = (targetRouter, sendOrdAddTaskId) => {
    const { jumpRouting } = this.props;
    if (targetRouter === 'sendOrdAddTaskId') {
      jumpRouting(targetRouter, sendOrdAddTaskId);
    } else {
      const recvOrdAddTaskId = sendOrdAddTaskId;
      jumpRouting(targetRouter, recvOrdAddTaskId);
    }
  };

  render() {
    const { addTaskList, loading } = this.props;
    const columns = [
      {
        title: '客户名称',
        dataIndex: 'custName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
      },
      {
        title: '签约方',
        dataIndex: 'sendCorpName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
      },
      {
        title: '接单方',
        dataIndex: 'recvSuppName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
      },
      {
        title: '状态',
        dataIndex: 'hdlName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
      },
      {
        title: '执行地',
        dataIndex: 'cityName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
      },
      {
        title: '发单时间',
        dataIndex: 'sendDate',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
        render: val => val && moment(val).format('YYYY-MM-DD HH:mm') || '--',
      },
      {
        title: '接单时间',
        dataIndex: 'recvDate',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder' } }),
        render: val => val && moment(val).format('YYYY-MM-DD HH:mm') || '--',
      },
      {
        title: '操作',
        dataIndex: 'operName',
        onHeaderCell: () => ({ style: { fontWeight: 'bolder', width: 150 } }),
        render: (text, record) => (
          <div>
            {record.suppFlag ? ( // 发单
              <span
                style={{ color: '#1890FF', cursor: 'pointer' }}
                onClick={() => this.jumpRouting('sendOrdAddTaskId', record.sendOrdAddTaskId)}
              >
                查看
              </span>
            ) : (
              // 接单
              <span
                style={{ color: '#1890FF', cursor: 'pointer' }}
                onClick={() => this.jumpRouting('recvOrdAddTaskId', record.recvOrdAddTaskId)}
              >
                查看
              </span>
            )}
          </div>
        ),
      },
    ];
    return (
      <div>
        <Card
          style={{ marginBottom: 12 }}
          title={<span style={{ fontWeight: 'bolder' }}>增员任务</span>}
          bordered={false}
          id="increasetask"
        >
          <StandardTable
            selectedRows={[]}
            selectedRowKeys={[]}
            loading={loading}
            data={addTaskList}
            rowSelection={null}
            columns={columns}
            rowKey="sendOrdAddTaskId"
            pagination={false}
          />
        </Card>
      </div>
    );
  }
}

export default EmpInfor;
